package com.bwie.user.controller;

import java.util.Arrays;
import java.util.Map;


import com.bwie.user.conf.OssUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.user.entity.GoodsEntity;
import com.bwie.user.service.GoodsService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;

import org.springframework.web.multipart.MultipartFile;


/**
 * 
 *
 * @author ShuangzhiZhao
 * @email 466505908@qq.com
 * @date 2022-02-22 11:01:47
 */
@RestController
@RequestMapping("user/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @Autowired
    private OssUtils ossUtils;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @RequestMapping("/list2")
    public R list2(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage2(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{gid}")
    public R info(@PathVariable("gid") Long gid){
		GoodsEntity goods = goodsService.getById(gid);

        return R.ok().setData(goods).put("goods", goods);
    }
    /**
     * 信息
     */
    @RequestMapping("/info2/{gid}")
    public GoodsEntity info2(@PathVariable("gid") Long gid){

        return goodsService.getById(gid);
    }

    /**
     * 图片上传
     */
    @RequestMapping("/upload")
    public R upload(MultipartFile file){
        R r = ossUtils.uploadFile(file);
        return r;
    }


    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GoodsEntity goods){
		goodsService.save(goods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GoodsEntity goods){
		goodsService.updateById(goods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] gids){
		goodsService.removeByIds(Arrays.asList(gids));

        return R.ok();
    }

}
